home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / X11 / Xpoll.h < prev    next >
C/C++ Source or Header  |  2006-04-12  |  7KB  |  222 lines

  1. /* $Xorg: Xpoll.h,v 1.4 2001/02/09 02:03:23 xorgcvs Exp $ */
  2.  
  3. /*
  4.  
  5. Copyright 1994, 1998  The Open Group
  6.  
  7. Permission to use, copy, modify, distribute, and sell this software and its
  8. documentation for any purpose is hereby granted without fee, provided that
  9. the above copyright notice appear in all copies and that both that
  10. copyright notice and this permission notice appear in supporting
  11. documentation.
  12.  
  13. The above copyright notice and this permission notice shall be included
  14. in all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. OTHER DEALINGS IN THE SOFTWARE.
  23.  
  24. Except as contained in this notice, the name of The Open Group shall
  25. not be used in advertising or otherwise to promote the sale, use or
  26. other dealings in this Software without prior written authorization
  27. from The Open Group.
  28.  
  29. */
  30. /* $XFree86: xc/include/Xpoll.h,v 3.8 2001/01/17 17:53:11 dawes Exp $ */
  31.  
  32. #ifndef _XPOLL_H_
  33. #define _XPOLL_H_
  34.  
  35. #ifndef WIN32
  36.  
  37. #ifndef USE_POLL
  38.  
  39. #include <X11/Xos.h>
  40. #if !defined(DGUX)
  41. #if (defined(SVR4) || defined(CRAY) || defined(AIXV3)) && !defined(FD_SETSIZE)
  42. #include <sys/select.h>
  43. #ifdef luna
  44. #include <sysent.h>
  45. #endif
  46. #endif
  47. #else /* DGUX  -- No sys/select in Intel DG/ux */
  48. #include <sys/time.h> 
  49. #include <sys/types.h>
  50. #include <unistd.h>
  51. #endif
  52.  
  53. #ifdef __QNX__  /* Make sure we get 256 bit select masks */
  54. #define FD_SETSIZE 256
  55. #include <sys/select.h>
  56. #endif
  57.  
  58. /* AIX 4.2 fubar-ed <sys/select.h>, so go to heroic measures to get it */
  59. #if defined(AIXV4) && !defined(NFDBITS)
  60. #include <sys/select.h>
  61. #endif
  62. #include <X11/Xmd.h>
  63. #ifdef CSRG_BASED
  64. #include <sys/param.h>
  65. # if BSD < 199103
  66. typedef long fd_mask;
  67. # endif
  68. #endif
  69.  
  70. #define XFD_SETSIZE    256
  71. #ifndef FD_SETSIZE
  72. #define FD_SETSIZE    XFD_SETSIZE
  73. #endif
  74.  
  75. #ifndef NBBY
  76. #define NBBY    8        /* number of bits in a byte */
  77. #endif
  78.  
  79. #ifndef NFDBITS
  80. #define NFDBITS (sizeof(fd_mask) * NBBY)    /* bits per mask */
  81. #endif
  82.  
  83. #ifndef howmany
  84. #define howmany(x,y)    (((x)+((y)-1))/(y))
  85. #endif
  86.  
  87. #ifdef BSD
  88. # if BSD < 198911    /* 198911 == OSF/1, 199103 == CSRG_BASED */
  89. #  ifndef luna        /* and even though on LUNA BSD ==  43, it has it */
  90. typedef struct fd_set {
  91.     fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
  92. } fd_set;
  93. #  endif
  94. # endif
  95. #endif
  96.  
  97. #ifndef hpux /* and perhaps old BSD ??? */
  98. # define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
  99. #else
  100. # ifndef _XPG4_EXTENDED /* HPUX 9.x and earlier */
  101. #  define Select(n,r,w,e,t) select(n,(int*)r,(int*)w,(int*)e,(struct timeval*)t)
  102. # else
  103. #  define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
  104. # endif
  105. #endif
  106.  
  107. #ifndef FD_SET
  108. #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= ((fd_mask)1 << ((n) % NFDBITS)))
  109. #endif
  110. #ifndef FD_CLR
  111. #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~((fd_mask)1 << ((n) % NFDBITS)))
  112. #endif
  113. #ifndef FD_ISSET
  114. #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & ((fd_mask)1 << ((n) % NFDBITS)))
  115. #endif
  116. #ifndef FD_ZERO
  117. #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
  118. #endif
  119.  
  120. /*
  121.  * The howmany(FD_SETSIZE, NFDBITS) computes the number of elements in the
  122.  * array. before accessing an element in the array we check it exists.
  123.  * If it does not exist then the compiler discards the code to access it. 
  124.  */
  125. #define XFD_ANYSET(p) \
  126.         ((howmany(FD_SETSIZE, NFDBITS) > 0 && (p)->fds_bits[0]) || \
  127.         (howmany(FD_SETSIZE, NFDBITS) > 1 && (p)->fds_bits[1]) || \
  128.         (howmany(FD_SETSIZE, NFDBITS) > 2 && (p)->fds_bits[2]) || \
  129.         (howmany(FD_SETSIZE, NFDBITS) > 3 && (p)->fds_bits[3]) || \
  130.         (howmany(FD_SETSIZE, NFDBITS) > 4 && (p)->fds_bits[4]) || \
  131.         (howmany(FD_SETSIZE, NFDBITS) > 5 && (p)->fds_bits[5]) || \
  132.         (howmany(FD_SETSIZE, NFDBITS) > 6 && (p)->fds_bits[6]) || \
  133.         (howmany(FD_SETSIZE, NFDBITS) > 7 && (p)->fds_bits[7]))
  134.  
  135. #define XFD_COPYSET(src,dst) { \
  136.         int __i__; \
  137.         for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
  138.             (dst)->fds_bits[__i__] = (src)->fds_bits[__i__]; \
  139.         }
  140. #define XFD_ANDSET(dst,b1,b2) { \
  141.         int __i__; \
  142.         for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
  143.             (dst)->fds_bits[__i__] = ((b1)->fds_bits[__i__] & (b2)->fds_bits[__i__]); \
  144.         }
  145. #define XFD_ORSET(dst,b1,b2) { \
  146.         int __i__; \
  147.         for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
  148.             (dst)->fds_bits[__i__] = ((b1)->fds_bits[__i__] | (b2)->fds_bits[__i__]); \
  149.         }        
  150. #define XFD_UNSET(dst,b1) { \
  151.         int __i__; \
  152.         for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
  153.             (dst)->fds_bits[__i__] &= ~((b1)->fds_bits[__i__]); \
  154.         }
  155.  
  156. #else /* USE_POLL */
  157. #include <sys/poll.h>
  158. #endif /* USE_POLL */
  159.  
  160. #else /* WIN32 */
  161.  
  162. #define XFD_SETSIZE    256
  163. #ifndef FD_SETSIZE
  164. #define FD_SETSIZE    XFD_SETSIZE
  165. #endif
  166. #include <X11/Xwinsock.h>
  167.  
  168. #define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
  169.  
  170. #define XFD_SETCOUNT(p)    (((fd_set FAR *)(p))->fd_count)
  171. #define XFD_FD(p,i) (((fd_set FAR *)(p))->fd_array[i])
  172. #define XFD_ANYSET(p)    XFD_SETCOUNT(p)
  173.  
  174. #define XFD_COPYSET(src,dst) { \
  175.     u_int __i; \
  176.     FD_ZERO(dst); \
  177.     for (__i = 0; __i < XFD_SETCOUNT(src) ; __i++) { \
  178.         XFD_FD(dst,__i) = XFD_FD(src,__i); \
  179.     } \
  180.     XFD_SETCOUNT(dst) = XFD_SETCOUNT(src); \
  181. }
  182.  
  183. #define XFD_ANDSET(dst,b1,b2) { \
  184.     u_int __i; \
  185.     FD_ZERO(dst); \
  186.     for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
  187.         if (FD_ISSET(XFD_FD(b1,__i), b2)) \
  188.        FD_SET(XFD_FD(b1,__i), dst); \
  189.     } \
  190. }
  191.  
  192. #define XFD_ORSET(dst,b1,b2) { \
  193.     u_int __i; \
  194.     XFD_COPYSET(b1,dst); \
  195.     for (__i = 0; __i < XFD_SETCOUNT(b2) ; __i++) { \
  196.         if (!FD_ISSET(XFD_FD(b2,__i), dst)) \
  197.        FD_SET(XFD_FD(b2,__i), dst); \
  198.     } \
  199. }
  200.  
  201. /* this one is really sub-optimal */
  202. #define XFD_UNSET(dst,b1) { \
  203.     u_int __i; \
  204.     for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
  205.     FD_CLR(XFD_FD(b1,__i), dst); \
  206.     } \
  207. }
  208.  
  209. /* we have to pay the price of having an array here, unlike with bitmasks
  210.    calling twice FD_SET with the same fd is not transparent, so be careful */
  211. #undef FD_SET
  212. #define FD_SET(fd,set) do { \
  213.     if (XFD_SETCOUNT(set) < FD_SETSIZE && !FD_ISSET(fd,set)) \
  214.         XFD_FD(set,XFD_SETCOUNT(set)++)=(fd); \
  215. } while(0)
  216.  
  217. #define getdtablesize() FD_SETSIZE 
  218.  
  219. #endif /* WIN32 */
  220.  
  221. #endif /* _XPOLL_H_ */
  222.